package com.mySchool.exception;


import com.mySchool.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

   /*  @ExceptionHandler
    public Result handleException(Exception e) {
        log.error("服务器出错", e);
        return Result.error("服务器出错, 联系管理员");
    }

    @ExceptionHandler
    public Result handleDuplicate(DuplicateKeyException e) {
        log.error("重复插入数据", e);
        String message = e.getMessage();
        int i = message.indexOf("Duplicate entry");
        String errMsg = message.substring(i);
        String[] arr = errMsg.split(" ");

        return Result.error(arr[2] + "已存在");
    } */
}
